<script setup>
import { ref, reactive, computed } from 'vue'
import { useRouter } from 'vue-router'


// 获取路由
const router = useRouter()

// 获取用户信息
const userInfo = computed(() => {
  return JSON.parse(localStorage.getItem('h5_user'))
})

// 是否退出弹窗
const isShowQuitDialog = ref(false)
// 退出登录
function logoOut() {
  localStorage.removeItem('h5_user')
  localStorage.removeItem('h5_token')

  location.href = location.origin
}

// 跳转订单页面
function goOrder(type) {
  router.push(`/order?active=${type}`)
}
</script>

<template>
  <div class="container">
    <div class="user">
      <van-image
        width="100"
        height="100"
        class="img"
        :src="userInfo.avatar"
      ></van-image>
      <div class="text">{{ userInfo.name }}</div>
    </div>
    <!-- 订单 -->
    <div class="order">
      <div class="top">
        <div class="text1">我的订单</div>
        <div class="text2">全部</div>
      </div>
      <div class="buttom">
        <div class="item">
          <van-image
            @click="goOrder(1)"
            width="40"
            height="40"
            src="/h5_images/od_10.png"
          ></van-image>
          <div>待支付</div>
        </div>
        <div class="item">
          <van-image
            @click="goOrder(2)"
            width="40"
            height="40"
            src="/h5_images/od_20.png"
          ></van-image>
          <div>待服务</div>
        </div>
        <div class="item">
          <van-image
            @click="goOrder(3)"
            width="40"
            height="40"
            src="/h5_images/od_40.png"
          ></van-image>
          <div>已完成</div>
        </div>
        <div class="item">
          <van-image
            @click="goOrder(4)"
            width="40"
            height="40"
            src="/h5_images/od_40.png"
          ></van-image>
          <div>已取消</div>
        </div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="foot">
      <div class="foot1">
        <div class="text1">
          <van-image
            width="20"
            height="20"
            src="h5_images/ic_clients.png"
            ></van-image>
            服务对象管理
        </div>
        <div class="text2">
          <van-icon name="arrow"></van-icon>
        </div>
      </div>
      <div class="foot2">
        <div class="text1">
          <van-image
            width="20"
            height="20"
            src="h5_images/ic_share.png"
            ></van-image>
            分享转发
        </div>
        <div class="text2">
          <van-icon name="arrow"></van-icon>
        </div>
      </div>
    </div>

    <!-- 退出按钮 -->
    <van-button @click="isShowQuitDialog=true" type="danger" size="large" class="quit">退出登录</van-button>

    <!-- 弹窗 -->
    <van-dialog
      v-model:show="isShowQuitDialog"
      title="提示"
      message="确定退出登录吗？"
      :show-cancel-button="true"
      @cancel="isShowQuitDialog = false"
      @confirm="logoOut"
    ></van-dialog>
  </div>
</template>

<style scoped lang="less">
.container {
  background-color: #f0f0f0;
  height: 100vh;
  overflow: hidden;
  .user {
    width: 95%;
    height: 200px;
    background-color: #fff;
    text-align: center;
    border-radius: 10px;
    margin: 10px;
    .img {
      margin-top: 30px;
    }
    .text {
      line-height: 30px;
      font-weight: bold;
    }
  }
  .order {
    width: 90%;
    margin: 10px;
    border-radius: 5px;
    background-color: #fff;
    padding: 10px;
    .top {
      margin: 10px;
      line-height: 50px;
      display: flex;
      justify-content: space-between;
      .text1 {
        color: #333;
      }
      .text2 {
        color: #999;
      }
      border-bottom: 0.5px solid #f5f5f5;
    }
    .buttom {
      padding: 10px;
      display: flex;
      justify-content: space-around;
      .item {
        font-size: 14px;
        color: #999;
      }
    }
  }
  .foot {
    margin: 0 10px;
    padding: 10px;
    line-height: 50px;
    background-color: #fff;
    .foot1,
    .foot2 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #555;
      .van-image {
        transform: translateY(3px);
      }
    }
    .foot1 {
      border-bottom: 0.5px solid #f5f5f5;
    }
  }
  .quit {
    width: 90%;
    margin: 20px;
  }
  .quit_text {
    margin: 20px 0;
    text-align: center;
  }
}
</style>
